function [lower_bounds, upper_bounds, PICP, PINAW, AIS] = bootstrapPI(test_actual, test_pred, train_error, B, alpha)

    % s = rng;
    
    n_train = length(train_error); % 训练集误差序列长度
    n_test = length(test_actual);  % 测试集实际序列长度

    % 初始化Bootstrap误差样本矩阵
    bootstrap_errors = zeros(B, n_train);

    % 生成B个Bootstrap样本
    for i = 1:B
        % 从训练集误差中随机抽样（有放回）
        bootstrap_sample = randsample(train_error, n_train, true);
        bootstrap_errors(i, :) = bootstrap_sample;
    end

    % 计算每个Bootstrap样本的预测区间
    lower_bounds = zeros(n_test, 1);
    upper_bounds = zeros(n_test, 1);
    
    % 对于每个测试集预测值，计算对应的预测区间
    for j = 1:n_test
        % 使用每个Bootstrap样本的误差来调整预测值
        adjusted_predictions = bootstrap_errors(:, 1);
        
        % 按百分位数计算预测区间
        lower_bounds(j) = test_pred(j) + prctile(adjusted_predictions, alpha/2* 100);
        upper_bounds(j) = test_pred(j) + prctile(adjusted_predictions, (1 - alpha/2)* 100);
    end

    best_lower_bounds = lower_bounds;
    best_upper_bounds = upper_bounds;
    % best_lower_bounds(best_lower_bounds<0) = 0;
    % best_upper_bounds(best_upper_bounds<0) = 0;

    PICP = calc_PICP(test_actual, best_lower_bounds, best_upper_bounds);
    PINAW = calc_PINAW(test_actual, best_lower_bounds, best_upper_bounds);
    
    % 显示结果
    fprintf('%d%%The confidence level corresponds to the coverage rate. (PICP): %.2f%%\n', (1-alpha)*100, PICP*100);
    fprintf('%d%%The confidence level corresponds to the average interval width. (PINAW): %.4f\n', (1-alpha)*100, PINAW);

    % CWC = calc_CWC(PINAW,PICP,alpha,8);
    % fprintf('%d%%The confidence levelCWC: %.4f\n', (1-alpha)*100, CWC);

    AIS = calc_AIS(test_actual, best_lower_bounds, best_upper_bounds, alpha);
    fprintf('%d%%Confidence level corresponds to the average interval score.(AIS): %.4f\n', (1-alpha)*100, AIS);

    % fprintf('%d%\n', s);
end
